package com.jrx.anytxn.customer.service;

import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.customer.dto.BaseApiReq;
import com.jrx.anytxn.customer.dto.coupon.CouponChargeOffReq;
import com.jrx.anytxn.customer.dto.coupon.CouponTrialReq;
import com.jrx.anytxn.customer.dto.coupon.CouponTrialRes;
import com.jrx.anytxn.customer.dto.rights.CmCustomerRightsRes;
import com.jrx.anytxn.customer.dto.rights.CustRightRes;
import com.jrx.anytxn.customer.dto.rights.CustomerRightRes;
import com.jrx.anytxn.customer.dto.rights.CustomerRightResByCms;
import com.jrx.anytxn.customer.entity.CmCustomerRightInfo;
import com.jrx.anytxn.customer.entity.TlRightsExchangeLog;
import com.jrx.anytxn.i18n.response.TxnPage;

import java.util.List;

/**
 * 客户权益信息接口
 * @author YAYALU
 */
public interface ICustomerRightService {

    /**
     * 获取客户权益信息
     * 
     * @param baseApiReq
     * @return
     * @throws TxnBizException
     */
    CustomerRightRes getCustomerRight(BaseApiReq baseApiReq) throws TxnBizException;

    /**
     * 根据以下条件查询客户权益信息
     * 
     * @param channel
     * @param customerId
     * @param tenantId
     * @param pageNum
     * @param pageSize
     * @return
     */
    TxnPage<CmCustomerRightsRes> getRightsWithPage(String channel, String customerId, String tenantId, Integer pageNum,
        Integer pageSize);

    /**
     * 根据客户权益id、客户号、租户号 查询客户权益信息
     * 
     * @param id
     * @param customerId
     * @param tenantId
     * @return
     */
    CmCustomerRightsRes getCustomerRightByIdAndCustomerId(Long id, String customerId, String tenantId);

    /**
     * 根据客户号 订单编号 查询客户权益信息
     * 
     * @param loanId
     * @param customerId
     * @param tenantId
     * @return
     * @throws TxnBizException
     */
    CustomerRightResByCms getCustomerRightByLoanIdAndCustomerId(String loanId, String customerId, String tenantId)
        throws TxnBizException;

    /**
     * 根据客户id 租户 订单号 查询权益信息
     * 
     * @param customerId
     * @param tenantId
     * @param loanId
     * @return
     * @throws TxnBizException
     */
    CmCustomerRightInfo getByCustomerIdAndTenantIdAndLoanId(String customerId, String tenantId, String loanId);;

    /**
     * 根据客户id 租户 订单号 查询权益信息
     * 
     * @param customerId
     * @param tenantId
     * @param custRightId
     * @return
     * @throws TxnBizException
     */
    CmCustomerRightInfo getRightInfoById(Long custRightId, String customerId, String tenantId) throws TxnBizException;;

    /**
     * 更新优惠券状态
     * 
     * @param custRightId
     * @param loanId
     * @param rightsStatus
     * @param customerId
     * @param tenantId
     */
    void updateCustRight(Long custRightId, String loanId, String rightsStatus, String customerId, String tenantId);

    /**
     * 根据 客户号、租户号、权益id、活动号 查询客户权益信息表
     * 
     * @param customerId
     * @param tenantId
     * @param rightsId
     * @param activityId
     * @return
     */
    CmCustomerRightInfo selectByCustomerIdAndTenantIdAndRightsIdAndActivityId(String customerId, String tenantId,
        String rightsId, String activityId);

    /**
     * 根据 客户号、租户号、权益资格id、活动号 查询客户权益信息表
     * 
     * @param customerId
     * @param tenantId
     * @param qualificationId
     * @param activityId
     * @return
     */
    List<CmCustomerRightInfo> selectByCustomerIdAndTenantIdAndQualificationIdAndActivityId(String customerId,
        String tenantId, String qualificationId, String activityId);

    /**
     * 根据客户id、租户号、权益类型列表 查询 客户权益信息
     * 
     * @param customerId
     * @param tenantId
     * @param rightsTypeList
     * @return
     */
    List<CustRightRes> getByCustomerIdAndTenantIdAndChannelAndRightsTypeList(String customerId, String tenantId, String channel,
        List<String> rightsTypeList);

    /**
     * 获取 客户指定权益类型 列表
     * 
     * @param userId
     * @param tenantId
     * @param rightsTypeList
     * @return
     */
    List<CustRightRes> listByCustomerRightsType(String userId, String tenantId, String channel,
                                                List<String> rightsTypeList) throws TxnBizException;

    /**
     * 优惠券 消费时现金抵消试算
     * @param trialReq
     * @return
     */
    CouponTrialRes couponTrial(CouponTrialReq trialReq) throws TxnBizException;

    /**
     * 优惠券 消费
     * @param couponChargeOffReq
     * @return
     */
    CouponTrialRes chargeOffCoupon(CouponChargeOffReq couponChargeOffReq) throws TxnBizException;

    /**
     * 批量保存
     * @param customerRightInfoList
     * @return int 返回影响条数
     */
    int insertBatch(List<CmCustomerRightInfo> customerRightInfoList);

    /**
     * 关联兑换记录ID
     * @param rightInfo
     * @param exchangeLogId
     */
    void updateRightExchangeId(CmCustomerRightInfo rightInfo, Long exchangeLogId);

    /**
     * 兑换一个用户权益资格，并扣减库存
     * @param rightInfo
     * @param rightsId
     */
    void updateRightToUsed(CmCustomerRightInfo rightInfo, String rightsId);

    /**
     * 恢复用户的权益资格
     * @param rightInfo
     */
    void resetRightToUnused(CmCustomerRightInfo rightInfo);

    /**
     * 根据客户ID和主键ID查询权益资格记录
     * @param id
     * @param customerId
     * @param tenantId
     * @return
     */
    CmCustomerRightInfo findRightInfoById(Long id, String customerId, String tenantId);

    /**
     * 根据权益兑换记录ID查询
     * @param customerId
     * @param tenantId
     * @param exchangeLogId
     * @return
     */
    CmCustomerRightInfo findRightInfoByExchangeLogId(String customerId, String tenantId, Long exchangeLogId);

}
